import $service from '../../../../service.js';
var user_id,this_;
var user_type="1";
var hospital_id = "1";
var log_id;
var selToID
Page({
	data: {
		imgAttay : [],//指定上传图片的集合
		opinion_content : '',
        opinion_phone:''
	},
	onLoad(e) {
        hospital_id=e.hospital_id;
        log_id=e.log_id;
        selToID = e.selToID
	},
	onShow:function(){
	   if(!$service.isUndefinedAndEmpty($service.getUserLocalStorage().user_type)){
	   		user_type = $service.getUserLocalStorage().user_type;
	   	}
	    if(user_type == 1){//1用户 1门店
	        user_id = $service.getUserLocalStorage().user_id;
	    }else{
	        user_id = $service.getUserLocalStorage().store_id;
	    }
	},
	save:function(){
        if(this.data.imgAttay.length == 0){
            $service.showToast('请先上传图片');
            return;
        }
		var jsonObj = {
            "hospital_id" : hospital_id,//医院id
            "log_id" : log_id,//问诊id
            "imgList":$service.jsonToStr(this.data.imgAttay)//图片
        }
		var jsonAjax = {   
			"url": "userSide_personal_inquiry_addInquiryLogImgList.do", 
			"jsonData": jsonObj,
		}
		console.log("意见反馈=="+JSON.stringify(jsonObj))
		$service.getAjaxData(jsonAjax,function(jsonObj) {
            var sendSystemMessageMsgText = '用户已上传图片'
            // wx.txTic.sendCustomMessage(selToID,2)
            wx.txTic.sendSystemMessageMsg(selToID,sendSystemMessageMsgText);
			wx.showToast({"title":'提交成功',"icon":"none",duration: 4000});
			setTimeout(function(){
				wx.navigateBack({
					delta:1
				})
			},1500);
		});
	},
	// 上传图片
	uploadImg:function(){
		this_ = this;
		if (this_.data.imgAttay.length === 3) { 
			wx.showToast({
				title: '一次最多上传3张，请分批上传',
				icon:"none",
				duration: 4000
			});
			return;  
		} 
		wx.chooseImage({
			count: 1,          
			success: function (res) {  
				const tempFilePaths = res.tempFilePaths; 
				wx.uploadFile({   
					 url: $service.path_url+'otherFile_fileEntityuploadimg_wx.do', //上传图片需要加图片前缀
					 filePath: tempFilePaths[0],
					 name: 'image',
					 success: (uploadFileRes) => {
					 	var imgObj = {};
					 	imgObj.img_src = $service.path_url_img+ uploadFileRes.data;
					 	this_.data.imgAttay = this_.data.imgAttay.concat(imgObj); 
					 	this_.setData({
					 		imgAttay:this_.data.imgAttay
					 	})
					 },   
				});
			},    
		});
	},  
	// 删除图片
	closeImg:function(e){
		var index = e.currentTarget.dataset.index;
		this.data.imgAttay.splice(index,1);
		this.setData({
			imgAttay:this.data.imgAttay
		})
	},
     lookimglist(e){
         wx.navigateTo({
             url: '../index_picturelist/index_picturelist?log_id=' + log_id +'&selToID=' + selToID
         })
     }
})

